home *** CD-ROM | disk | FTP | other *** search
/ Programmer Power Tools / Programmer Power Tools.iso / progjrn / pj_vga.arc / VGA65-L2.ASM < prev    next >
Assembly Source File  |  1988-08-18  |  4KB  |  182 lines

  1. Copyright Michael Abrash, 1988.  All Rights Reserved.
  2. ;
  3. ; Program to demonstrate the 32 text pages of the VGA/EGA.
  4. ;
  5. ; To demonstrate the 32 text pages of the VGA, set
  6. ; ADAPTER_IS_VGA to 1.
  7. ;
  8. ; To demonstrate the 32 text pages of the EGA, set
  9. ; ADAPTER_IS_VGA to 0.
  10. ;
  11. ; By Michael Abrash  5/22/88
  12. ;
  13.  
  14. ADAPTER_IS_VGA        equ    0
  15. PAGE_LENGTH        equ    1000h    ;number of bytes per page
  16. MISCELLANEOUS_OUTPUT_W    equ    3c2h    ;Miscellaneous Output write port
  17. MISCELLANEOUS_OUTPUT_R    equ    3cch    ;Miscellaneous Output read port
  18. GC_INDEX        equ    3ceh
  19. GC_MISCELLANEOUS    equ    6
  20. CRTC_INDEX        equ    3d4h
  21. CRTC_START_ADDRESS_HIGH    equ    0ch
  22. CRTC_START_ADDRESS_LOW    equ    0dh
  23.  
  24. stack    segment    para stack 'STACK'
  25.     db    512 dup (?)
  26. stack    ends
  27.  
  28. code    segment para public 'CODE'
  29.     assume    cs:code, ds:nothing
  30. start    proc    near
  31. ;
  32. ; Set to text mode.
  33. ;
  34.     mov    ax,3
  35.     int    10h
  36. ;
  37. ; Relocate display memory to A000 by reprogramming
  38. ; the Graphics Controller's Miscellaneous register.
  39. ;
  40.     mov    dx,GC_INDEX
  41.     mov    al,GC_MISCELLANEOUS
  42.     out    dx,al
  43.     inc    dx
  44.     mov    al,06h
  45.     out    dx,al
  46. ;
  47. ; Point to display memory.
  48. ;
  49.     mov    ax,0a000h
  50.     mov    es,ax
  51. ;
  52. ; Fill text pages 0-15 (the pages that are accessible when
  53.  
  54. ; the Page bit is 1, the setting after a mode set is performed).
  55. ; (Page 0 is filled with "A", page 1 with "B", and so on.)
  56. ;
  57.     sub    ax,ax    ;start with page 0
  58.     mov    bl,'A'    ;base letter for pages 0-15
  59. FillPages0_15Loop:
  60.     push    ax
  61.     call    FillPage
  62.     pop    ax
  63.     inc    ax
  64.     cmp    ax,16
  65.     jb    FillPages0_15Loop
  66. ;
  67. ; Set the Page bit to 0.
  68. ;
  69. if ADAPTER_IS_VGA
  70.     mov    dx,MISCELLANEOUS_OUTPUT_R
  71.     in    al,dx
  72.     and    al,not 20h    ;Page bit (bit 5) -> 0
  73.     mov    dx,MISCELLANEOUS_OUTPUT_W
  74.     out    dx,al
  75. else
  76.     mov    dx,MISCELLANEOUS_OUTPUT_W
  77.     mov    al,87h        ;Page bit (bit 5) -> 0
  78.     out    dx,al
  79. endif
  80. ;
  81. ; Now fill text pages 16-31 (the pages that are accessible when
  82. ; the Page bit is 0).
  83. ; (Page 16 is filled with "Q", page 17 with "R", and so on.)
  84. ;
  85.     sub    ax,ax    ;start with page 0
  86.     mov    bl,'Q'    ;base letter for pages 16-31
  87. FillPages16_31Loop:
  88.     push    ax
  89.     call    FillPage
  90.     pop    ax
  91.     inc    ax
  92.     cmp    ax,16
  93.     jb    FillPages16_31Loop
  94. ;
  95. ; Display each of the text pages in turn, waiting for a key
  96. ; before going to the next page. Note that all 32 pages can
  97. ; be displayed without changing the Page bit; the Page bit
  98. ; only affects CPU accesses, not video data fetching.
  99. ;
  100.     sub    ax,ax
  101. ShowPageLoop:
  102.     push    ax
  103.     call    ShowPage
  104.     call    WaitKey
  105.     pop    ax
  106.     inc    ax
  107.     cmp    ax,32
  108.     jb    ShowPageLoop
  109. ;
  110. ; Done-perform a mode set to reset all paging and clear
  111. ; the screen, then return to DOS.
  112. ;
  113.     mov    ax,3
  114.     int    10h
  115.     mov    ah,4ch
  116.     int    21h
  117. start    endp
  118. ;
  119. ; Fills a text page with a corresponding character.
  120. ;
  121. ; Input:
  122. ;    AX = text page
  123. ;    BL = character for text page 0 (each text page
  124. ;        is filled with character BL + text page #)
  125. ;
  126. FillPage    proc    near
  127.     push    ax    ;save the page #
  128.     mov    dx,PAGE_LENGTH
  129.     mul    dx    ;calculate the start offset of the page
  130.             ; in the display memory segment
  131.     mov    di,ax
  132.     pop    ax    ;get back the page #
  133.     add    al,bl    ;convert it to a unique letter
  134.     mov    ah,7    ;attribute is white
  135.     mov    cx,PAGE_LENGTH/2 ;page length as measured
  136.                  ; in character/attribute pairs
  137.     cld
  138.     rep    stosw    ;fill the page
  139.     ret
  140. FillPage    endp
  141. ;
  142. ; Programs the CRTC to display the desired text page.
  143. ;
  144. ; Input: AX = text page.
  145. ;
  146. ShowPage    proc    near
  147.     mov    dx,PAGE_LENGTH/2
  148.     mul    dx        ;start offset of the pages as
  149.                 ; measured in character/attribute
  150.                 ; pairs (which is how the CRTC
  151.                 ; counts in text mode)
  152.     mov    dx,CRTC_INDEX    ;point to the CRTC Index register
  153.     push    ax
  154.     mov    al,CRTC_START_ADDRESS_HIGH
  155.     out    dx,al
  156.     inc    dx        ;point to the CRTC Data register
  157.     mov    al,ah
  158.     out    dx,al        ;set the high start address byte
  159.     dec    dx        ;point to the CRTC Index register
  160.     mov    al,CRTC_START_ADDRESS_LOW
  161.     out    dx,al
  162.     inc    dx        ;point to the CRTC Data register
  163.     pop    ax
  164.     out    dx,al        ;set the low start address byte
  165.     ret
  166. ShowPage    endp
  167. ;
  168. ; Waits until a key is pressed.
  169. ;
  170. WaitKey    proc    near
  171.     mov    ah,1
  172.     int    16h
  173.     jz    WaitKey
  174.     sub    ah,ah
  175.     int    16h    ;clear the key
  176.     ret
  177. WaitKey    endp
  178.  
  179. code    ends
  180.     end    start
  181.  
  182.